package api;

import utils.CommUtils;
import utils.HttpUtils;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

/**
 * 手机号核验API接口
 */
public class MobileApi extends AccessToken {
    private final static String mobileElem2URI = "/aip/check/v1/mobile/elem2";
    private final static String mobileElem3URI = "/aip/check/v1/mobile/elem3";

    private final static String mobileElem3DetailURI = "/aip/check/v1/mobile/elem3detail";
    private final static String mobileOnlineURI = "/aip/check/v1/mobile/online";


    /**
     * 1.手机二要素核验接口
     */
    public static void mobileElem2(String _BizNo, String idName, String phoneNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, mobileElem2URI, getCachedAccessToken(), paramsMap);
        System.out.println("手机二要素核验接口-- >> mobileElem2:" + res);
    }

    /**
     * 2.手机三要素核验接口(简版)
     */
    public static void mobileElem3(String _BizNo, String idName, String idNumber, String phoneNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, mobileElem3URI, getCachedAccessToken(), paramsMap);
        System.out.println("手机三要素核验接口-- >> mobileElem3:" + res);
    }

    /**
     * 3.手机三要素核验接口(详版)
     * 通过手机号、姓名、身份证号进行核查身份信息是否一致，如不一致时，返回详细的核查结果信息
     */
    public static void mobileElem3Detail(String _BizNo, String idName, String idNumber, String phoneNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, mobileElem3DetailURI, getCachedAccessToken(), paramsMap);
        System.out.println("手机三要素核验接口-- >> mobileElem3:" + res);
    }

    /**
     * 4.手机在网时长查询
     */
    public static void mobileOnline(String _BizNo, String phoneNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, mobileOnlineURI, getCachedAccessToken(), paramsMap);
        System.out.println("手机在网时长查询-- >> mobileOnline:" + res);
    }

    public static void main(String[] args) {
        //手机二要素核验接口
        mobileElem2(UUID.randomUUID().toString(), "张三", "150124747xx");
        //手机三要素核验接口
        mobileElem3(UUID.randomUUID().toString(), "张三", "44080419xx06080xxx", "150124747xx");
        //手机三要素核验接口(详版)
        mobileElem3Detail(UUID.randomUUID().toString(), "张三", "440804199x0xxxxxx", "150124747xx");
        //手机在网时长查询
        mobileOnline(UUID.randomUUID().toString(), "150124747xx");
    }

}
